package com.xxx.video.commen.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;


public class LocationUtils {
//    //声明AMapLocationClient类对象
//    public static AMapLocationClient mLocationClient = null;
//
//    //声明AMapLocationClientOption对象
//    public static AMapLocationClientOption mLocationOption = null;
    /**
     * get location
     *
     * @param activity          activity
     * @param onSuccessListener listener
     */
    @SuppressLint("MissingPermission")
    public static void getLocation(Activity activity, OnSuccessListener onSuccessListener) {
        if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity) != ConnectionResult.SUCCESS) {
            if (onSuccessListener != null) {
                onSuccessListener.onSuccess(null);
            }
        } else {
            FusedLocationProviderClient fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(activity);
            fusedLocationProviderClient.getLastLocation().
                    addOnSuccessListener(onSuccessListener);
        }
//        //初始化定位
//        mLocationClient = new AMapLocationClient(activity);
//        //初始化AMapLocationClientOption对象
//        mLocationOption = new AMapLocationClientOption();
//        mLocationOption.setOnceLocation(true);
//        mLocationClient.setLocationOption(mLocationOption);
//        //设置定位回调监听
//        mLocationClient.setLocationListener(aMapLocation -> {
//            if (onSuccessListener != null) {
//                onSuccessListener.onSuccess(aMapLocation);
//            }
//        });
//        mLocationClient.startLocation();
    }
}
